<template>
  <div class="broadcast" v-if="broadcast_buy_log && broadcast_buy_log.list.length > 0">
    <div class="broadcastBox" v-if="broadcast_buy_log">
      <div class="broadcast-top" v-if="broadcast_buy_log && broadcast_buy_log.list.length > 0">
        <div class="broadcast-top-title">购买记录</div>
        <i class="iconfont icon-icon_more11" @click="toRecord"></i>
      </div>
      <div class="broadcast-list" v-if="broadcast_buy_log" :style="{ height: heightMath }">
        <swiper :options="swiperOption" ref="storeSwiper" :key="swiperKey">
          <swiper-slide v-for="(item, index) in broadcast_buy_log.list" :key="index">
            <div class="broadcast-lis">
              <img :src="item.avatar_image" class="broadcast-img" alt="" />
              <span>{{ item.content }}</span>
            </div>
          </swiper-slide>
        </swiper>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: ["broadcast_buy_log", "goods_id"],
  watch: {
    broadcast_buy_log(newVal) {
      this.swiperOption.loopedSlides = Number(this.broadcast_buy_log.list.length) + 2;
    }
  },
  computed: {
    heightMath() {
      let hei = this.swiperOption.height;
      if (this.broadcast_buy_log) {
        // 动态设置高度
        hei = this.broadcast_buy_log.column_number * hei;
      }
      return `${hei}px`;
    }
  },
  activated() {
    this.$nextTick(() => {
      // 初始化
      this.swiperKey++;
    });
  },
  data() {
    return {
      swiperKey: 0,
      swiperOption: {
        direction: "vertical",
        height: 64,
        autoplay: {
          disableOnInteraction: false,
          delay: 1000 //1秒切换一次
        },
        pagination: false,
        loop: true,
        watchOverflow: false,
        loopedSlides: 0
      }
    };
  },
  mounted() {},
  methods: {
    toRecord() {
      this.$router.push(this.fun.getUrl("broadcast_record", {},{goods_id:this.goods_id}));
    }
  }
};
</script>
<style lang="scss" scoped>
.broadcastBox {
  margin: 10px;
  background: #fff;
  padding: 0.6rem;
  border-radius: 10px;
}
.broadcast-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  .broadcast-top-title {
    font-weight: 500;
    font-size: 0.94rem;
    color: #00001c;
  }
  .icon-icon_more11 {
    font-size: 0.75rem;
    color: #aaaab3;
  }
}
.broadcast-list {
  overflow: hidden;
  position: relative;
  .broadcast-lis {
    height: 100%;
    display: flex;
    align-items: center;
    .broadcast-img {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      margin: 0;
      margin-right: 0.25rem;
    }
  }
}
.broadcast-list::after {
  content: "";
  position: absolute;
  width: 100%;
  bottom: 0;
  left: 0;
  height: 40px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.34) 0%, #ffffff 100%);
  border-radius: 0.5rem 0.5rem 0.5rem 0.5rem;
  z-index: 999;
}
</style>
